Skip to content

Fix: Prevent kspaceFirstOrder3D from modifying input source and sensor#613

Closed
waltsims wants to merge 1 commit intomasterfrom
fix-bug-600-kspacefirstorder3d-input-modification
Closed

Fix: Prevent kspaceFirstOrder3D from modifying input source and sensor#613
waltsims wants to merge 1 commit intomasterfrom
fix-bug-600-kspacefirstorder3d-input-modification

Conversation

@waltsims
Copy link
Copy Markdown
Owner

The kspaceFirstOrder3D simulation function was unintentionally modifying the input source and sensor objects. This occurred because the internal kWaveSimulation object and its helper functions were operating directly on these mutable input objects.

This commit addresses the issue by:

  1. Modifying kWaveSimulation.__init__ to create deep copies of the input source and sensor objects. All internal operations within kWaveSimulation and its helper functions (like save_to_disk_func and retract_transducer_grid_size) now use these copies. The original objects you passed remain unchanged.

  2. Adding a regression test (tests/test_kspaceFirstOrder3D_state.py). This test verifies that critical attributes of the source and sensor objects (e.g., source.p0, sensor.mask) are not altered after calls to kspaceFirstOrder3D, and that the function can be called multiple times with the same input objects without error or state corruption.

This ensures that the source and sensor states remain consistent, allowing them to be reused for multiple simulations or checkpointing without unexpected side effects, resolving bug #600.

…sensor

The kspaceFirstOrder3D simulation function was unintentionally modifying
the input `source` and `sensor` objects. This occurred because the
internal `kWaveSimulation` object and its helper functions were
operating directly on these mutable input objects.

This commit addresses the issue by:
1. Modifying `kWaveSimulation.__init__` to create deep copies of the
   input `source` and `sensor` objects. All internal operations within
   `kWaveSimulation` and its helper functions (like `save_to_disk_func`
   and `retract_transducer_grid_size`) now use these copies.
   The original objects you passed remain unchanged.

2. Adding a regression test (`tests/test_kspaceFirstOrder3D_state.py`).
   This test verifies that critical attributes of the `source` and
   `sensor` objects (e.g., `source.p0`, `sensor.mask`) are not altered
   after calls to `kspaceFirstOrder3D`, and that the function can be
   called multiple times with the same input objects without error or
   state corruption.

This ensures that the `source` and `sensor` states remain consistent,
allowing them to be reused for multiple simulations or checkpointing
without unexpected side effects, resolving bug #600.
@waltsims waltsims closed this May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant